use dta\Turnout_District_Level, clear 

drop SMD_margin_quantile
xtile SMD_margin_quantile=SMD_margin, nq(6)

bysort year SMD_margin_quantile: egen mean_turnout=mean(turnout)
label var mean_turnout "Mean Voter Turnout"
bysort year SMD_margin_quantile: egen sd_turnout=sd(turnout)
label var sd_turnout "Standard Deviation of Voter Turnout"

foreach quantile in 1 2 3 4 5 6 {
foreach depvar in mean_turnout {
twoway (scatter `depvar' year if year<1920 & SMD_margin_quantile==`quantile', mstyle(p1) lstyle(p1) lpattern(dash) connect(l)) ///
(scatter `depvar' year if year>1920 & SMD_margin_quantile==`quantile', mstyle(p1) lstyle(p1) lpattern(dash) connect(l)), ///
title(Quantile `quantile') graphregion(fcolor(white)) scheme(s2mono) legend(off) ytitle("") xtitle("") xscale(range(1909 1927)) xlabel(1909[3]1927) 
graph save figures\gph\_`depvar'_comp_`quantile'.gph, replace
}
}

cd figures\gph\
graph combine _mean_turnout_comp_1.gph _mean_turnout_comp_2.gph _mean_turnout_comp_3.gph _mean_turnout_comp_4.gph _mean_turnout_comp_5.gph _mean_turnout_comp_6.gph , xcommon ycommon graphregion(fcolor(white)) scheme(s2mono) row(3) col(2)
*graph export ..\_mean_turnout_split_q6.eps, replace
*graph export ..\_mean_turnout_split_q6.tif, replace
graph export ..\Figure6.eps, replace
graph export ..\Figure6.tif, replace

cd ..\..\
